home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / GDebi / GDebiCommon.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  5.9 KB  |  144 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import os
  6. import string
  7. import warnings
  8. warnings.filterwarnings('ignore', 'apt API not stable yet', FutureWarning)
  9. from mimetypes import guess_type
  10. import apt
  11. import apt_pkg
  12. from DebPackage import DebPackage, Cache
  13. import gettext
  14.  
  15. def _(str):
  16.     return utf8(gettext.gettext(str))
  17.  
  18.  
  19. def utf8(str):
  20.     if isinstance(str, unicode):
  21.         return str
  22.     
  23.     try:
  24.         return unicode(str, 'UTF-8')
  25.     except:
  26.         isinstance(str, unicode)
  27.         return unicode(str, 'latin1')
  28.  
  29.  
  30.  
  31. class GDebiCommon(object):
  32.     
  33.     def __init__(self, datadir, options, file = ''):
  34.         self.cprogress = None
  35.         self.deps = ''
  36.         self.version_info_title = ''
  37.         self.version_info_msg = ''
  38.         self._deb = None
  39.         self._options = options
  40.         self.install = []
  41.         self.remove = []
  42.         self.unauthenticated = 0
  43.  
  44.     
  45.     def openCache(self):
  46.         self._cache = Cache(self.cprogress)
  47.         if self._cache._depcache.BrokenCount > 0:
  48.             self.error_header = _('Broken dependencies')
  49.             self.error_body = _("Your system has broken dependencies. This application can not continue until this is fixed. To fix it run 'gksudo synaptic' or 'sudo apt-get install -f' in a terminal window.")
  50.             return False
  51.         return True
  52.  
  53.     
  54.     def open(self, file):
  55.         
  56.         try:
  57.             self._deb = DebPackage(self._cache, file)
  58.         except (IOError, SystemError):
  59.             e = None
  60.             mimetype = guess_type(file)
  61.             if mimetype[0] != None and mimetype[0] != 'application/x-debian-package':
  62.                 self.error_header = _("'%s' is not a Debian package") % os.path.basename(file)
  63.                 self.error_body = _("The MIME type of this file is '%s' and can not be installed on this system.") % mimetype[0]
  64.                 return False
  65.             self.error_header = _("Could not open '%s'") % os.path.basename(file)
  66.             self.error_body = _('The package might be corrupted or you are not allowed to open the file. Check the permissions of the file.')
  67.             return False
  68.         except:
  69.             mimetype[0] != 'application/x-debian-package'
  70.  
  71.  
  72.     
  73.     def compareDebWithCache(self):
  74.         res = self._deb.compareToVersionInCache(useInstalled = False)
  75.         if not (self._options.non_interactive) and res != DebPackage.NO_VERSION:
  76.             pkg = self._cache[self._deb.pkgName]
  77.             if res == DebPackage.VERSION_SAME:
  78.                 if self._cache.downloadable(pkg, useCandidate = True):
  79.                     self.version_info_title = _('Same version is available in a software channel')
  80.                     self.version_info_msg = _('You are recommended to install the software from the channel instead.')
  81.                 
  82.             elif res == DebPackage.VERSION_IS_NEWER:
  83.                 if self._cache.downloadable(pkg, useCandidate = True):
  84.                     self.version_info_title = _('An older version is available in a software channel')
  85.                     self.version_info_msg = _('Generally you are recommended to install the version from the software channel, since it is usually better supported.')
  86.                 
  87.             elif res == DebPackage.VERSION_OUTDATED:
  88.                 if self._cache.downloadable(pkg, useCandidate = True):
  89.                     self.version_info_title = _('A later version is available in a software channel')
  90.                     self.version_info_msg = _('You are strongly advised to install the version from the software channel, since it is usually better supported.')
  91.                 
  92.             
  93.         
  94.  
  95.     
  96.     def getChanges(self):
  97.         (self.install, self.remove, self.unauthenticated) = self._deb.requiredChanges
  98.         self.deps = ''
  99.         if len(self.install) == len(self.install):
  100.             pass
  101.         elif len(self.install) == 0:
  102.             self.deps = _('All dependencies are satisfied')
  103.         
  104.         return True
  105.  
  106.     
  107.     def try_acquire_lock(self):
  108.         ''' check if we can lock the apt database '''
  109.         
  110.         try:
  111.             apt_pkg.PkgSystemLock()
  112.         except SystemError:
  113.             self.error_header = _('Only one software management tool is allowed to run at the same time')
  114.             self.error_body = _("Please close the other application e.g. 'Update Manager', 'aptitude' or 'Synaptic' first.")
  115.             return False
  116.  
  117.         apt_pkg.PkgSystemUnLock()
  118.         return True
  119.  
  120.     
  121.     def acquire_lock(self):
  122.         ''' lock the pkgsystem for install '''
  123.         if self._deb is None:
  124.             return False
  125.         
  126.         try:
  127.             apt_pkg.PkgSystemLock()
  128.         except SystemError:
  129.             self._deb is None
  130.             self._deb is None
  131.             self.error_header = _('Only one software management tool is allowed to run at the same time')
  132.             self.error_body = _("Please close the other application e.g. 'Update Manager', 'aptitude' or 'Synaptic' first.")
  133.             return False
  134.  
  135.         return True
  136.  
  137.     
  138.     def release_lock(self):
  139.         ''' release the pkgsystem lock '''
  140.         apt_pkg.PkgSystemLock()
  141.         return True
  142.  
  143.  
  144.